/*
 * Germinus
 */
package org.germinus.telcoblocks.infraestructuras.diagram.rcp.part;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.gmf.runtime.notation.View;
import org.germinus.telcoblocks.Centralita_VOIP;
import org.germinus.telcoblocks.Enlace;
import org.germinus.telcoblocks.MediaServer;
import org.germinus.telcoblocks.Nodo;
import org.germinus.telcoblocks.Servidor_APP_SIP;
import org.germinus.telcoblocks.Servidor_VOIP;
import org.germinus.telcoblocks.SoftPhone_VOIP;
import org.germinus.telcoblocks.TelcoblocksPackage;
import org.germinus.telcoblocks.Telefono_VOIP;
import org.germinus.telcoblocks.Terminal;
import org.germinus.telcoblocks.infraestructuras.diagram.rcp.edit.parts.Centralita_VOIPEditPart;
import org.germinus.telcoblocks.infraestructuras.diagram.rcp.edit.parts.EnlaceEditPart;
import org.germinus.telcoblocks.infraestructuras.diagram.rcp.edit.parts.MediaServerEditPart;
import org.germinus.telcoblocks.infraestructuras.diagram.rcp.edit.parts.REDEditPart;
import org.germinus.telcoblocks.infraestructuras.diagram.rcp.edit.parts.Servidor_APP_SIPEditPart;
import org.germinus.telcoblocks.infraestructuras.diagram.rcp.edit.parts.Servidor_VOIPEditPart;
import org.germinus.telcoblocks.infraestructuras.diagram.rcp.edit.parts.SoftPhone_VOIPEditPart;
import org.germinus.telcoblocks.infraestructuras.diagram.rcp.edit.parts.Telefono_VOIPEditPart;
import org.germinus.telcoblocks.infraestructuras.diagram.rcp.providers.TelcoblocksElementTypes;

/**
 * @generated
 */
public class TelcoblocksDiagramUpdater {

	/**
	 * @generated
	 */
	public static List getSemanticChildren(View view) {
		switch (TelcoblocksVisualIDRegistry.getVisualID(view)) {
		case REDEditPart.VISUAL_ID:
			return getRED_1000SemanticChildren(view);
		}
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getRED_1000SemanticChildren(View view) {
		if (!view.isSetElement()) {
			return Collections.EMPTY_LIST;
		}
		org.germinus.telcoblocks.RED modelElement = (org.germinus.telcoblocks.RED) view
				.getElement();
		List result = new LinkedList();
		for (Iterator it = modelElement.getTerminales().iterator(); it
				.hasNext();) {
			Terminal childElement = (Terminal) it.next();
			int visualID = TelcoblocksVisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == SoftPhone_VOIPEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
				continue;
			}
			if (visualID == Telefono_VOIPEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
				continue;
			}
		}
		{
			Servidor_VOIP childElement = modelElement.getServidor_VOIP();
			int visualID = TelcoblocksVisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == Servidor_VOIPEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
			}
		}
		{
			MediaServer childElement = modelElement.getMediaServer();
			int visualID = TelcoblocksVisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == MediaServerEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
			}
		}
		{
			Servidor_APP_SIP childElement = modelElement.getServidor_APP_SIP();
			int visualID = TelcoblocksVisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == Servidor_APP_SIPEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
			}
		}
		{
			Centralita_VOIP childElement = modelElement.getCentralita_VOIP();
			int visualID = TelcoblocksVisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == Centralita_VOIPEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
			}
		}
		return result;
	}

	/**
	 * @generated
	 */
	public static List getContainedLinks(View view) {
		switch (TelcoblocksVisualIDRegistry.getVisualID(view)) {
		case REDEditPart.VISUAL_ID:
			return getRED_1000ContainedLinks(view);
		case SoftPhone_VOIPEditPart.VISUAL_ID:
			return getSoftPhone_VOIP_2001ContainedLinks(view);
		case Servidor_VOIPEditPart.VISUAL_ID:
			return getServidor_VOIP_2002ContainedLinks(view);
		case MediaServerEditPart.VISUAL_ID:
			return getMediaServer_2003ContainedLinks(view);
		case Servidor_APP_SIPEditPart.VISUAL_ID:
			return getServidor_APP_SIP_2004ContainedLinks(view);
		case Centralita_VOIPEditPart.VISUAL_ID:
			return getCentralita_VOIP_2005ContainedLinks(view);
		case Telefono_VOIPEditPart.VISUAL_ID:
			return getTelefono_VOIP_2006ContainedLinks(view);
		case EnlaceEditPart.VISUAL_ID:
			return getEnlace_4001ContainedLinks(view);
		}
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getIncomingLinks(View view) {
		switch (TelcoblocksVisualIDRegistry.getVisualID(view)) {
		case SoftPhone_VOIPEditPart.VISUAL_ID:
			return getSoftPhone_VOIP_2001IncomingLinks(view);
		case Servidor_VOIPEditPart.VISUAL_ID:
			return getServidor_VOIP_2002IncomingLinks(view);
		case MediaServerEditPart.VISUAL_ID:
			return getMediaServer_2003IncomingLinks(view);
		case Servidor_APP_SIPEditPart.VISUAL_ID:
			return getServidor_APP_SIP_2004IncomingLinks(view);
		case Centralita_VOIPEditPart.VISUAL_ID:
			return getCentralita_VOIP_2005IncomingLinks(view);
		case Telefono_VOIPEditPart.VISUAL_ID:
			return getTelefono_VOIP_2006IncomingLinks(view);
		case EnlaceEditPart.VISUAL_ID:
			return getEnlace_4001IncomingLinks(view);
		}
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getOutgoingLinks(View view) {
		switch (TelcoblocksVisualIDRegistry.getVisualID(view)) {
		case SoftPhone_VOIPEditPart.VISUAL_ID:
			return getSoftPhone_VOIP_2001OutgoingLinks(view);
		case Servidor_VOIPEditPart.VISUAL_ID:
			return getServidor_VOIP_2002OutgoingLinks(view);
		case MediaServerEditPart.VISUAL_ID:
			return getMediaServer_2003OutgoingLinks(view);
		case Servidor_APP_SIPEditPart.VISUAL_ID:
			return getServidor_APP_SIP_2004OutgoingLinks(view);
		case Centralita_VOIPEditPart.VISUAL_ID:
			return getCentralita_VOIP_2005OutgoingLinks(view);
		case Telefono_VOIPEditPart.VISUAL_ID:
			return getTelefono_VOIP_2006OutgoingLinks(view);
		case EnlaceEditPart.VISUAL_ID:
			return getEnlace_4001OutgoingLinks(view);
		}
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getRED_1000ContainedLinks(View view) {
		org.germinus.telcoblocks.RED modelElement = (org.germinus.telcoblocks.RED) view
				.getElement();
		List result = new LinkedList();
		result
				.addAll(getContainedTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getSoftPhone_VOIP_2001ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getServidor_VOIP_2002ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getMediaServer_2003ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getServidor_APP_SIP_2004ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getCentralita_VOIP_2005ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getTelefono_VOIP_2006ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getEnlace_4001ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getSoftPhone_VOIP_2001IncomingLinks(View view) {
		SoftPhone_VOIP modelElement = (SoftPhone_VOIP) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getServidor_VOIP_2002IncomingLinks(View view) {
		Servidor_VOIP modelElement = (Servidor_VOIP) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getMediaServer_2003IncomingLinks(View view) {
		MediaServer modelElement = (MediaServer) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getServidor_APP_SIP_2004IncomingLinks(View view) {
		Servidor_APP_SIP modelElement = (Servidor_APP_SIP) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getCentralita_VOIP_2005IncomingLinks(View view) {
		Centralita_VOIP modelElement = (Centralita_VOIP) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getTelefono_VOIP_2006IncomingLinks(View view) {
		Telefono_VOIP modelElement = (Telefono_VOIP) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getEnlace_4001IncomingLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getSoftPhone_VOIP_2001OutgoingLinks(View view) {
		SoftPhone_VOIP modelElement = (SoftPhone_VOIP) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getServidor_VOIP_2002OutgoingLinks(View view) {
		Servidor_VOIP modelElement = (Servidor_VOIP) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getMediaServer_2003OutgoingLinks(View view) {
		MediaServer modelElement = (MediaServer) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getServidor_APP_SIP_2004OutgoingLinks(View view) {
		Servidor_APP_SIP modelElement = (Servidor_APP_SIP) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getCentralita_VOIP_2005OutgoingLinks(View view) {
		Centralita_VOIP modelElement = (Centralita_VOIP) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getTelefono_VOIP_2006OutgoingLinks(View view) {
		Telefono_VOIP modelElement = (Telefono_VOIP) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getEnlace_4001OutgoingLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	private static Collection getContainedTypeModelFacetLinks_Enlace_4001(
			org.germinus.telcoblocks.RED container) {
		Collection result = new LinkedList();
		for (Iterator links = container.getEnlaces().iterator(); links
				.hasNext();) {
			EObject linkObject = (EObject) links.next();
			if (false == linkObject instanceof Enlace) {
				continue;
			}
			Enlace link = (Enlace) linkObject;
			if (EnlaceEditPart.VISUAL_ID != TelcoblocksVisualIDRegistry
					.getLinkWithClassVisualID(link)) {
				continue;
			}
			Nodo dst = link.getDestino();
			Nodo src = link.getOrigen();
			result.add(new TelcoblocksLinkDescriptor(src, dst, link,
					TelcoblocksElementTypes.Enlace_4001,
					EnlaceEditPart.VISUAL_ID));
		}
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection getIncomingTypeModelFacetLinks_Enlace_4001(
			Nodo target, Map crossReferences) {
		Collection result = new LinkedList();
		Collection settings = (Collection) crossReferences.get(target);
		for (Iterator it = settings.iterator(); it.hasNext();) {
			EStructuralFeature.Setting setting = (EStructuralFeature.Setting) it
					.next();
			if (setting.getEStructuralFeature() != TelcoblocksPackage.eINSTANCE
					.getEnlace_Destino()
					|| false == setting.getEObject() instanceof Enlace) {
				continue;
			}
			Enlace link = (Enlace) setting.getEObject();
			if (EnlaceEditPart.VISUAL_ID != TelcoblocksVisualIDRegistry
					.getLinkWithClassVisualID(link)) {
				continue;
			}
			Nodo src = link.getOrigen();
			result.add(new TelcoblocksLinkDescriptor(src, target, link,
					TelcoblocksElementTypes.Enlace_4001,
					EnlaceEditPart.VISUAL_ID));
		}
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection getOutgoingTypeModelFacetLinks_Enlace_4001(
			Nodo source) {
		org.germinus.telcoblocks.RED container = null;
		// Find container element for the link.
		// Climb up by containment hierarchy starting from the source
		// and return the first element that is instance of the container class.
		for (EObject element = source; element != null && container == null; element = element
				.eContainer()) {
			if (element instanceof org.germinus.telcoblocks.RED) {
				container = (org.germinus.telcoblocks.RED) element;
			}
		}
		if (container == null) {
			return Collections.EMPTY_LIST;
		}
		Collection result = new LinkedList();
		for (Iterator links = container.getEnlaces().iterator(); links
				.hasNext();) {
			EObject linkObject = (EObject) links.next();
			if (false == linkObject instanceof Enlace) {
				continue;
			}
			Enlace link = (Enlace) linkObject;
			if (EnlaceEditPart.VISUAL_ID != TelcoblocksVisualIDRegistry
					.getLinkWithClassVisualID(link)) {
				continue;
			}
			Nodo dst = link.getDestino();
			Nodo src = link.getOrigen();
			if (src != source) {
				continue;
			}
			result.add(new TelcoblocksLinkDescriptor(src, dst, link,
					TelcoblocksElementTypes.Enlace_4001,
					EnlaceEditPart.VISUAL_ID));
		}
		return result;
	}

}
